package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.Board;

@Repository (value="boardDao")
public class BoardDaoImpl implements BoardDao {

	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSqlSessionTemplate(SqlSessionFactory sqlSessionFactory ) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	
	public List<Board> list() {
		List<Board> list = null;
		
		try {
			list = sqlSessionTemplate.selectList("boardlist");
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
		return list;
	}

	public Board view(long boardNo) {
		Board board = new Board();

		try {
			board = sqlSessionTemplate.selectOne("boardview", boardNo);
		} catch (Exception e) {
			
			e.printStackTrace();
		}

		return board;
	}

	public int add(Board board) {

		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("boardadd",board);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int modify(Board board) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("boardmodify",board);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int remove(long boardNo) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("boardremove",boardNo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
